<?php  session_start();
/**
* @package		Parents@School
* @copyright	                Copyright (C) 2008 Kristof Beckers. All rights reserved.
* @Version		2.0
* @license		GNU/GPL, see LICENSE.php
**/
include ("../include/config.php");
require_once ("../include/db.php");
//include ("../include/header.php");

// username and password sent from form
$myusername=$_POST['username'];
$password = $_POST['passwd'];
$mypassword = md5($password);

$sqladmin = "SELECT * FROM $tbstaff WHERE username='$myusername' AND password='$mypassword' ";
$resultadmin=mysql_query($sqladmin);

while ($rowadmin = mysql_fetch_array($resultadmin)) {
   $username =  $rowadmin['username'];  
   $password = $rowadmin['password'];
   $usernameid = $rowadmin['ID'];
   $isadmin = $rowadmin['admin'];
}

// Mysql_num_row is counting table row
$countadmin=mysql_num_rows($resultadmin);
// If result matched $myusername and $mypassword, table row must be 1 row

if($countadmin==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername'] = $myusername ;
$_SESSION['admin'] = $isadmin;

}
if ($_SESSION['admin'] == "$adminid"){
	header("location:../admin/index.php");
	}
?>
